<?php 
/*
 * @Descripttion: 同步政府接口
 * @version: v1
 * @Author: Terry
 * @Date: 2020-09-15 16:27:31
 * @LastEditors: Terry
 * @LastEditTime: 2024-07-29 12:28:20
 */
namespace app\video\extend\libs;
use think\facade\Db;


class SwooleAsync {

    private $domain = "127.0.0.1";
    private $client;
    /**
     * @description: 构造函数，获取项目的配置（对接什么政府对应的配置）
     * @Author: Terry
     * @Date: 2022-04-20 19:25:46
     * @param {*} $prjCode
     */    
    public function __construct(){
        $this->client = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
        $this->domain = env('swoole.domain');
    }

    /**
     * @description: 可自定义发送的数据
     * @Author: Terry
     * @Date: 2022-05-20 17:03:49
     * @param $data 发送的数据
     */    
    private function send($data){
        $this->client->send(json_encode($data).PHP_EOL);
    }
    /**
     * @description: 进行政府数据同步
     * @Author: Terry
     * @Date: 2022-05-12 10:34:43
     * @param string $prjCode 项目唯一码
     * @param string $module 模块 
     * @param string $func 
     * @param array $data 
     */    
    public function swoole($func,$data){
        $ret = $this->client->connect($this->domain, 10000);
        if(!empty($ret)){
            $data = compact('func','data');
            $this->send($data);
            $this->client->close();
        }
    }

?>